﻿
using System.Runtime.Intrinsics.Arm;
using System.Runtime.Intrinsics.X86;

namespace getab
{
     public class getaandb
    {   static double a = 0;
        static double b = 0;
        public static void getab()
        {
            List<Point> points = getpoints.points;

            Point point;
            for (int i = 0; i < points.Count; i++)//将y轴变为ln y
            {
                point.X = points[i].X;
                point.Y = Math.Log(points[i].Y);
                points[i] = point; 
            }
            

            double averx = 0; 
            double avery = 0;
            double sumx = 0;
            double sumy = 0;
            foreach (Point m in points)//求x，y的总和
            {
               
                sumx += m.X;
                sumy += m.Y;
            }
            averx = sumx/points.Count;
            avery = sumy/points.Count;
            double numerator = 0;//b的分子
            double denominator = 0;//b的分母
            foreach (Point m in points)
            {
                double numrator1 = (m.X - averx) * (m.Y - avery);
                numerator += numrator1;//求分子
                double denominator1 = (m.X - averx) * (m.X - averx);
                denominator += denominator1;//求分母
            }
             b = numerator / denominator;
             a = avery - (b * averx);
            
        }
        public static double prediction(int m)
        { double prediction = a + b * m;
            prediction = Math.Pow(Math.E, prediction);
            return prediction;
        }





    }
}
